package com.eling.elcms.travel.dao.hibernate;

import com.eling.elcms.core.dao.hibernate.GenericDaoHibernate;
import com.eling.elcms.travel.dao.IPlanItemDao;
import com.eling.elcms.travel.model.PlanItem;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class PlanItemDaoHibernate extends GenericDaoHibernate<PlanItem, Long> implements IPlanItemDao{

	public PlanItemDaoHibernate(){
		super(PlanItem.class);
	}

	@Override
	public List<PlanItem> inquirySignup(List<PlanItem> list) {
		StringBuffer pkPlanItem = new StringBuffer();
		for (PlanItem planItem : list) {
			pkPlanItem.append(planItem.getPkPlanItem());
			pkPlanItem.append(",");
		}
		StringBuffer hql = new StringBuffer();
		hql.append("select * from travel_planitem where pk = (" + 
				"select pk from travel_signupregister where (" + 
				"select count(*) from travel_signupregister where pk in('"+pkPlanItem+"')) > 0)");
		Query query = getSession().createQuery(hql.toString());
		@SuppressWarnings("unchecked")
		List<PlanItem> result = query.list();
		return result;
	}
}
